﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class SysShopBuyCard
    {
        private readonly Chain.IDAL.SysShopBuyCard dal = new Chain.IDAL.SysShopBuyCard();

        public int Add(Chain.Model.SysShopBuyCard model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.SysShopBuyCard> DataTableToList(DataTable dt)
        {
            List<Chain.Model.SysShopBuyCard> list = new List<Chain.Model.SysShopBuyCard>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.SysShopBuyCard item = new Chain.Model.SysShopBuyCard();
                    if ((dt.Rows[i]["BuyCardID"] != null) && (dt.Rows[i]["BuyCardID"].ToString() != ""))
                    {
                        item.BuyCardID = int.Parse(dt.Rows[i]["BuyCardID"].ToString());
                    }
                    if ((dt.Rows[i]["StartCardNumber"] != null) && (dt.Rows[i]["StartCardNumber"].ToString() != ""))
                    {
                        item.StartCardNumber = dt.Rows[i]["StartCardNumber"].ToString();
                    }
                    if ((dt.Rows[i]["EndCardNumber"] != null) && (dt.Rows[i]["EndCardNumber"].ToString() != ""))
                    {
                        item.EndCardNumber = dt.Rows[i]["EndCardNumber"].ToString();
                    }
                    if ((dt.Rows[i]["BuyCardShopid"] != null) && (dt.Rows[i]["BuyCardShopid"].ToString() != ""))
                    {
                        item.BuyCardShopid = int.Parse(dt.Rows[i]["BuyCardShopid"].ToString());
                    }
                    if ((dt.Rows[i]["UserID"] != null) && (dt.Rows[i]["UserID"].ToString() != ""))
                    {
                        item.UserID = int.Parse(dt.Rows[i]["UserID"].ToString());
                    }
                    if ((dt.Rows[i]["Remark"] != null) && (dt.Rows[i]["Remark"].ToString() != ""))
                    {
                        item.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    if ((dt.Rows[i]["BuyCardTime"] != null) && (dt.Rows[i]["BuyCardTime"].ToString() != ""))
                    {
                        item.BuyCardTime = DateTime.Parse(dt.Rows[i]["BuyCardTime"].ToString());
                    }
                    if ((dt.Rows[i]["BuyCardMoney"] != null) && (dt.Rows[i]["BuyCardMoney"].ToString() != ""))
                    {
                        item.BuyCardMoney = decimal.Parse(dt.Rows[i]["BuyCardMoney"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int BuyCardID)
        {
            return this.dal.Delete(BuyCardID);
        }

        public bool DeleteList(string BuyCardIDlist)
        {
            return this.dal.DeleteList(BuyCardIDlist);
        }

        public bool Exists(int BuyCardID)
        {
            return this.dal.Exists(BuyCardID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, strWhere, out resCount);
        }

        public Chain.Model.SysShopBuyCard GetModel(int BuyCardID)
        {
            return this.dal.GetModel(BuyCardID);
        }

        public List<Chain.Model.SysShopBuyCard> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.SysShopBuyCard model)
        {
            return this.dal.Update(model);
        }
    }
}

